package com.juzipi.demo.handler;

import com.juzipi.demo.utils.StringUtils;
import com.juzipi.demo.utils.json.JsonAuthentication;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 注销的操作
 */

@Component
public class MyLogoutHandler extends JsonAuthentication implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        String token = httpServletRequest.getHeader("token");

        if (StringUtils.isNotEmpty(token)){
            SecurityContextHolder.clearContext();
        }

    }
}
